<template>
  <div id="footer1">
    <div class="modal fade" id="invite-user" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
              <span aria-hidden="true">&times;</span>
              <span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title">邀请好友，双方都可获赠实验豆！</h4>
          </div>
          <div class="modal-body">
            <h4>
              <p>
                <a href="#sign-modal" data-toggle="modal" data-sign="signin">登录</a>后邀请好友注册，您和好友将分别获赠3个实验豆！
              </p>
            </h4>

            <div id="msg-modal"></div>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fade" id="flash-message" tabindex="-1" role="dialog">
      <div class="modal-dialog" rolw="document"></div>
    </div>

    <div class="modal fade" id="sign-modal" tabindex="-1" role="dialog">
      <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
          <button type="button" class="close-modal" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
          <div class="modal-body">
            <ul class="nav nav-tabs" role="tablist">
              <li role="presentation" class="active">
                <a href="#signin-form" aria-controls="signin-form" role="tab" data-toggle="tab">登录</a>
              </li>
              <li role="presentation">
                <a href="#signup-form" aria-controls="signup-form" role="tab" data-toggle="tab">注册</a>
              </li>
            </ul>
            <div class="tab-content">
              <div role="tabpanel" class="tab-pane active" id="signin-form">
                <form action method="post" @submit.prevent="onLogin">
                  <div class="form-group">
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-lock" style="margin:0;"></i>
                      </div>
                      <input
                        type="text"
                        v-model="username"
                        class="form-control"
                        placeholder="请输入用户名"
                      />
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-lock" style="margin:0;"></i>
                      </div>
                      <input
                        type="password"
                        v-model="password"
                        class="form-control"
                        placeholder="请输入密码"
                      />
                    </div>
                  </div>
                  <div class="form-inline verify-code-item" style="display:none;">
                    <div class="form-group">
                      <div class="input-group">
                        <input
                          type="text"
                          name="captcha_v"
                          class="form-control"
                          placeholder="请输入验证码"
                        />
                      </div>
                    </div>
                    <img class="verify-code" src source="http://127.0.0.1:8000/captcha6/" />
                  </div>
                  <div class="form-group remember-login">
                    <input name="remember" type="checkbox" value="y" /> 下次自动登录
                    <a class="pull-right" href="reset_password/index.html">忘记密码？</a>
                  </div>
                  <div class="form-group">
                    <input class="btn btn-primary" name="submit" type="submit" value="进入实验楼" />
                  </div>
                  <div class="form-group widget-signin">
                    <span>快速登录</span>
                    <a href="/auth/qq?next=">
                      <i class="fa fa-qq"></i>
                    </a>
                    <a href="/api/get_url/">
                      <i class="fa fa-weibo"></i>
                    </a>
                    <a href="/auth/weixin?next=">
                      <i class="fa fa-weixin"></i>
                    </a>
                    <a href="/auth/github?next=">
                      <i class="fa fa-github"></i>
                    </a>
                    <a href="/auth/renren?next=">
                      <i class="fa fa-renren"></i>
                    </a>
                  </div>
                  <!-- <div class="form-group error-msg">
                    <div class="alert alert-danger" role="alert"></div>
                  </div> -->
                </form>
              </div>
              <div role="tabpanel" class="tab-pane" id="signup-form">
                <form action method="post" @submit.prevent="onSubmit">
                  <div class="form-group">
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-envelope" style="margin:0;"></i>
                      </div>
                      <input type="email" v-model="email" class="form-control" placeholder="请输入邮箱" />
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-user" style="margin:0;"></i>
                      </div>
                      <input
                        type="text"
                        name="username"
                        v-model="username"
                        class="form-control"
                        placeholder="请输入用户名"
                      />
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-lock" style="margin:0;"></i>
                      </div>
                      <input
                        type="password"
                        v-model="password"
                        class="form-control"
                        placeholder="请输入密码"
                      />
                    </div>
                  </div>
                  <div class="form-inline">
                    <div class="form-group">
                      <div class="input-group">
                        <input
                          type="text"
                          v-model="captcha_v"
                          class="form-control"
                          placeholder="请输入验证码"
                        />
                      </div>
                    </div>
                    <img class="verify-code" src source="http://127.0.0.1:8000/captcha6/" />
                  </div>
                  <div class="form-group">
                    <input class="btn btn-primary" name="submit" type="submit" value="注册" />
                  </div>
                  <div class="form-group agree-privacy">
                    注册表示您已经同意我们的
                    <a href="privacy/index.html" target="_blank">隐私条款</a>
                  </div>
                  <div class="form-group widget-signup">
                    <span>快速注册</span>
                    <a href="/auth/qq?next=">
                      <i class="fa fa-qq"></i>
                    </a>
                    <a href="/api/get_url/">
                      <i class="fa fa-weibo"></i>
                    </a>
                    <a href="/auth/weixin?next=">
                      <i class="fa fa-weixin"></i>
                    </a>
                    <a href="/auth/github?next=">
                      <i class="fa fa-github"></i>
                    </a>
                    <a href="/auth/renren?next=">
                      <i class="fa fa-renren"></i>
                    </a>
                  </div>
                  <!-- <div class="form-group error-msg">
                                <div class="alert alert-danger" role="alert"></div>
                  </div>-->
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fade" id='myModalss' tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-body">
                        <div role="tabpanel" class="tab-pane" >
                        <form action="" method="post" @submit.prevent="onSubmit2">
                            <div class="form-group agree-privacy">
                                请输入邮箱绑定第三方账号
                            </div>
                            <div class="form-group">
                                <div class="input-group">
                                    <div class="input-group-addon">
                                        <i class="fa fa-envelope" style="margin:0;"></i>
                                    </div>
                                    <input type="email" v-model="email2" class="form-control" placeholder="请输入邮箱">
                                </div>
                            </div>
                            <div class="form-group">
                                <input class="btn btn-primary" name="submit" type="submit" value="绑定">
                            </div>

                        </form>
                    </div>
            </div>
        </div>
        </div>
    </div>
    <div class="footer">
      <div class="container">
        <div class="row">
          <div class="col-md-4 clearfix footer-col">
            <img src="/static/img/logo_03.png" />
            <div class="footer-slogan">动手做实验，轻松学编程</div>
            <div class="col-xs-2">
              <div class="social-item footer-weixin-item">
                <i class="fa fa-weixin"></i>
                <div class="footer-weixin">
                  <img src="/static/img/footer-weixin.png" />
                </div>
              </div>
            </div>
            <div class="col-xs-2">
              <div class="social-item footer-qq-item">
                <i class="fa fa-qq"></i>
              </div>
            </div>
            <div class="col-xs-2">
              <div class="social-item footer-weibo-item">
                <a href="http://weibo.com/shiyanlou2013" target="_blank">
                  <i class="fa fa-weibo"></i>
                </a>
              </div>
            </div>
          </div>
          <div class="col-xs-6 col-sm-3 col-md-2 footer-col">
            <div class="col-title">公司</div>
            <a href="/privacy/index.html" target="_blank">关于我们</a>
            <br />
            <a href="/privacy/index.html" target="_blank">联系我们</a>
            <br />
            <a href="http://www.simplecloud.cn/jobs.html" target="_blank">加入我们</a>
            <br />
            <a href="https://blog.shiyanlou.com" target="_blank">技术博客</a>
            <br />
          </div>
          <div class="col-xs-6 col-sm-3 col-md-2 footer-col">
            <div class="col-title">合作</div>
            <a href="/privacy/index.html" target="_blank">我要投稿</a>
            <br />
            <a href="/static/labs/index.html" target="_blank">教师合作</a>
            <br />
            <a href="edu/index.html" target="_blank">高校合作</a>
            <br />
            <a href="/privacy/index.html" target="_blank">友情链接</a>
          </div>
          <div class="col-xs-6 col-sm-3 col-md-2 footer-col">
            <div class="col-title">服务</div>
            <a href="bootcamp/index.html" target="_blank">实战训练营</a>
            <br />
            <a href="/static/vip/index.html" target="_blank">会员服务</a>
            <br />
            <a href="courses/reports.html" target="_blank">实验报告</a>
            <br />
            <a
              href="questions/index.html?tag=%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98"
              target="_blank"
            >常见问题</a>
            <br />
            <a href="privacy/index.html" target="_blank">隐私条款</a>
          </div>
          <div class="col-xs-6 col-sm-3 col-md-2 footer-col">
            <div class="col-title">学习路径</div>
            <a href="paths/index.html" target="_blank">Python学习路径</a>
            <br />
            <a href="paths/index.html" target="_blank">Linux学习路径</a>
            <br />
            <a href="paths/index.html" target="_blank">大数据学习路径</a>
            <br />
            <a href="paths/index.html" target="_blank">Java学习路径</a>
            <br />
            <a href="paths/index.html" target="_blank">PHP学习路径</a>
            <br />
            <a href="paths/index.html" target="_blank">全部</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Register, Login, getWebourl, Senduid, Register2 } from "../api/api.js";
export default {
  name: "footer1",
  data() {
    return {
      email: "1115181384@qq.com",
      email2: "",
      password: "123456",
      captcha_v: "",
      username: "niejianqiang",
      weibourl: "",
      uid: ""
    };
  },
  methods: {
    onSubmit: function() {
      var params = {
        email: this.email,
        password: this.password,
        sms_code: this.captcha_v,
        username: this.username
      };
      Register(params).then(res => {
        console.log(res);
        if (res.code == 200) {
          alert(res.mess);
          this.$router.go(0);
        }
      });
    },
    onSubmit2: function() {
      var params = {
        email: this.email2,
        uid: this.uid
      };
      console.log(params);
      Register2(params).then(res => {
        console.log(res);
        if (res.code == 200) {
          alert("登陆成功");

          localStorage.setItem("username", res.username);
          localStorage.setItem("user_id", res.user_id);
          localStorage.setItem("token", res.token);
          localStorage.setItem("level", res.level);
          window.location.href = "http://localhost:8080/";
        } else {
          alert("登陆成功");

          localStorage.setItem("username", res.username);
          localStorage.setItem("user_id", res.user_id);
          localStorage.setItem("token", res.token);
          localStorage.setItem("level", res.level);

          window.location.href = "http://localhost:8080/";
        }
      });
    },
    onLogin: function() {
      var params = {
        password: this.password,
        username: this.username
      };
      console.log(params);
      Login(params).then(res => {
        if (res.code == 200) {
          alert("登陆成功");
          localStorage.setItem("username", res.username);
          localStorage.setItem("token", res.token);
          localStorage.setItem("user_id", res.user_id);
          localStorage.setItem("level", res.level);
          this.$router.go(0);
        }
      });
    },
    getUid: function() {
      this.uid = this.$route.query.uid;
      if (this.uid) {
          var params = {
          uid: this.uid
        };
        Senduid(params).then(res => {
          console.log(111)
          console.log(res);
          if (res.code == 200) {
            alert("登陆成功");
            localStorage.setItem("username", res.username);
            localStorage.setItem("token", res.token);
            localStorage.setItem("user_id", res.user_id);
            localStorage.setItem("level", res.level);
            window.location.href = "http://localhost:8080/";
          } else if (res.code == 20002) {
            //输入邮箱 绑定用户k
            $("#myModalss").modal("show");
          }
        });
      }
    }
  },
  mounted() {
    this.getUid();
  }
};
</script>

<style scoped>
</style>
